package com.czy.owner.ui.bottom;

import android.Manifest;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.czy.owner.R;
import com.czy.owner.adapter.BaseRecyclerAdapter;
import com.czy.owner.adapter.PackageExpandableAdapter;
import com.czy.owner.adapter.StoreGoodsListTagAdapter;
import com.czy.owner.adapter.StorePopuMenuSelectAdapter;
import com.czy.owner.api.BindStoreApi;
import com.czy.owner.api.BulletinListApi;
import com.czy.owner.api.NearStoreListApi;
import com.czy.owner.api.OwnStoreBannerApi;
import com.czy.owner.api.OwnerStoreInfoApi;
import com.czy.owner.api.StoreGoodsListByTagApi;
import com.czy.owner.api.StorePackageApi;
import com.czy.owner.callback.RecycleViewDivider;
import com.czy.owner.db.UserHelper;
import com.czy.owner.entity.BulletinModel;
import com.czy.owner.entity.ChainStoresModel;
import com.czy.owner.entity.EnpandableStorePackageEntity;
import com.czy.owner.entity.MyStoreGoodsListTagEntity;
import com.czy.owner.entity.NearStoreListModel;
import com.czy.owner.entity.OwnerInfoModel;
import com.czy.owner.entity.StoreDataModel;
import com.czy.owner.entity.StoreDetailBannersModel;
import com.czy.owner.entity.StoreDetailInfoModel;
import com.czy.owner.entity.StoreGoodsListTagEntity;
import com.czy.owner.entity.StorePackageEntity;
import com.czy.owner.entity.WebViewRequestParam;
import com.czy.owner.global.Constants;
import com.czy.owner.net.api.BaseResultEntity;
import com.czy.owner.net.http.HttpManager;
import com.czy.owner.net.listener.HttpOnNextListener;
import com.czy.owner.net.utils.JsonUtil;
import com.czy.owner.permission.Acp;
import com.czy.owner.permission.AcpListener;
import com.czy.owner.permission.AcpOptions;
import com.czy.owner.rxbus.RxBus;
import com.czy.owner.rxbus.Subscribe;
import com.czy.owner.rxbus.ThreadMode;
import com.czy.owner.rxbus.event.CommonEvent;
import com.czy.owner.ui.AdvertisingActivity;
import com.czy.owner.ui.BaseFragment;
import com.czy.owner.ui.MainActivity;
import com.czy.owner.ui.WebViewActivity;
import com.czy.owner.ui.accountbalance.RechargeActivity;
import com.czy.owner.ui.coupons.GetCouponsCenterActivity;
import com.czy.owner.ui.hotshop.GoodsDetailActivity;
import com.czy.owner.ui.hotshop.GoodsListActivity;
import com.czy.owner.ui.hotshop.HotShopClassifyActivity;
import com.czy.owner.ui.order.SelectBespokeActivity;
import com.czy.owner.ui.packagecardproject.BuyStorePackageActivity;
import com.czy.owner.ui.packagecardproject.PackageCardDetailActivity;
import com.czy.owner.ui.packagecardproject.PackageCardProjectActivity;
import com.czy.owner.ui.seckill.SecKillActivity;
import com.czy.owner.ui.store.BulletinListActivity;
import com.czy.owner.ui.store.NoBindStoreDetailActivity;
import com.czy.owner.ui.store.PaidActivity;
import com.czy.owner.ui.store.StoreListActivity;
import com.czy.owner.ui.store.StoreMoreActivity;
import com.czy.owner.utils.IntentUtils;
import com.czy.owner.utils.MyLog;
import com.czy.owner.utils.PhoneUtils;
import com.czy.owner.utils.SharedPreferencesUtils;
import com.czy.owner.utils.glide.GlideUtils;
import com.czy.owner.widget.ImageCycleView;
import com.czy.owner.widget.MyRecyclerView;
import com.czy.owner.widget.RoundImageView;
import com.czy.owner.widget.UniversalDialog;
import com.czy.owner.widget.guidehelp.DisplayUtils;
import com.czy.owner.widget.guidehelp.GuideHelper;
import com.czy.owner.widget.marqueeview.MarqueeView;
import com.easemob.cases.MessageHelper;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;
import com.easyrecycleview.decoration.DividerGridItemDecoration;
import com.easyrecycleview.decoration.DividerGridItemDecoration2;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
import com.zxing.library.CaptureActivity;
import com.zxing.library.ZXingConstants;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.functions.Consumer;

import static android.app.Activity.RESULT_OK;
import static com.czy.owner.entity.WebViewRequestParam.REQUEST_POST;


/**
 * Created by wangyng on 2017/5/2 0002.
 * 门店
 */

public class StoreFragment2 extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener {
    Handler mHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            switch (msg.what) {
                case REFRESH_BIND_COMPLETE:

                    storeGoodsListTagAdapter1.clear();
                    storeGoodsListTagAdapter2.clear();
                    storeGoodsListTagAdapter3.clear();

                    getStoreInfoData();
                    getHotGoods2();
                    getChainStoreData();
                    getBannersData();
                    getBulletin();
                    getStorePackage();
                    mSwipeLayout.setRefreshing(false);
                    mLoadView.CancleLoadView();
                    break;
                case REFRESH_UNBIND_COMPLETE:
                    imgUnbindScan.setVisibility(View.VISIBLE);
                    if ((Build.VERSION.SDK_INT >= 23)) {
                        getPermissions();
                    } else {
                        initUnbindStore();
                    }
                    mSwipeLayout.setRefreshing(false);
                    mLoadView.CancleLoadView();
                    break;
            }
            return false;
        }


    });


    private static final int REFRESH_BIND_COMPLETE = 0X110;
    private static final int REFRESH_UNBIND_COMPLETE = 0X111;
    public static final int NOBIND_TYPE = 0x11;
    public static final int BIND_TYPE = 0x22;
    private static final int STORE_TYPE = 1;
    //    wangyang 2017-11-09修改
    @BindView(R.id.ll_unbind_view)
    LinearLayout llUnbindView;
    @BindView(R.id.ll_bind_view)
    LinearLayout llBindView;

//    @BindView(R.id.img_popuwindow_menu)
//    ImageView imgPopuwindowMenu;
    @BindView(R.id.img_store_head_portrait)
    RoundImageView imgStoreHeadPortrait;
    @BindView(R.id.tv_store_name)
    TextView tvStoreName;
    @BindView(R.id.img_store_view)
    ImageCycleView mAdView;
    @BindView(R.id.marqueeView)
    MarqueeView marqueeView;

    @BindView(R.id.img_store_banner)
    ImageView imgStoreBanner;
    @BindView(R.id.tv_unbind_store_name)
    TextView tvUnbindStoreName;
    @BindView(R.id.tv_location)
    TextView tvLocation;
    @BindView(R.id.tv_distance)
    TextView tvDistance;
    @BindView(R.id.img_unbind_scan)
    ImageView imgUnbindScan;
    @BindView(R.id.rl_no_login_tip)
    RelativeLayout rlNoLoginTip;


    //    新增wangyang2017-12-19
    @BindView(R.id.swipe_refresh)
    SwipeRefreshLayout mSwipeLayout;
    @BindView(R.id.scrollView)
    ScrollView scrollView;
    @BindView(R.id.ll_goods1)
    LinearLayout llGoods1;
    @BindView(R.id.ll_goods2)
    LinearLayout llGoods2;
    @BindView(R.id.ll_goods3)
    LinearLayout llGoods3;
    @BindView(R.id.rv_goods1)
    MyRecyclerView rvGoods1;
    @BindView(R.id.rv_goods2)
    MyRecyclerView rvGoods2;
    @BindView(R.id.rv_goods3)
    MyRecyclerView rvGoods3;
    @BindView(R.id.ll_store_goods1)
    LinearLayout llStoreGoods1;
    @BindView(R.id.ll_store_goods2)
    LinearLayout llStoreGoods2;
    @BindView(R.id.ll_store_goods3)
    LinearLayout llStoreGoods3;


    //    wangyang 2018.3.26 门店新增推荐套餐
    @BindView(R.id.ll_recommend_store_package)
    LinearLayout llRecommendStorePackage;
    @BindView(R.id.rv_store_package)
    MyRecyclerView rvStorePackage;

    private PopupWindow popupwindow;
    private StorePopuMenuSelectAdapter homePopMenuAdapter;
    private List<ChainStoresModel> mChainStoresList = null;
    private RecyclerView poprecycleview;
    private AMapLocationClient locationClient = null;
    private AMapLocationClientOption locationOption = null;
    //标识，用于判断是否只显示一次定位信息和用户重新定位
    private boolean isFirstLoc = true;

    private ArrayList<String> mImageUrl = new ArrayList<>();//banner切换list
    private ArrayList<String> mImageUrlweb = new ArrayList<>();//banner的点击

    private List<StoreDetailBannersModel> bannersModel = new ArrayList<>();
    private RxPermissions rxPermissions;
    private List<BulletinModel.ListBean> bulletinModelList = new ArrayList<>();//公告集合
    private OwnerInfoModel ownerInfoModel = null;

    private NearStoreListModel nearStoreListModelOne;
    private List<NearStoreListModel> mNearlist = new ArrayList<>();

    private StoreGoodsListTagAdapter storeGoodsListTagAdapter1;
    private StoreGoodsListTagAdapter storeGoodsListTagAdapter2;
    private StoreGoodsListTagAdapter storeGoodsListTagAdapter3;

    private PackageExpandableAdapter packageExpandableAdapter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.fragment_store2;
    }

    @Override
    protected void initInjector() {

    }

    @Subscribe(code = Constants.SELECT_STORE_BESPOKE_ID, threadMode = ThreadMode.MAIN)
    public void eventPaidSuccess(CommonEvent successEvent) {
    }

    /*接受事件*/
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void event(ChainStoresModel model) {
        selectStore(model);
        MyLog.e("yang", "接受事件");

    }


    @Override
    protected void initViews() {

        RxBus.getDefault().register(this);
        ownerInfoModel = UserHelper.getInstance().getOwnerInfoModel(getActivity());
        rxPermissions = new RxPermissions(getActivity());
        int bindStoreId = (int) SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0);
        MyLog.e("yang", "bindStoreId==" + bindStoreId);
        if (bindStoreId != 0) {
            initBindStore();
        } else {
            onRefresh();
            //是否弹出门店绑定弹窗
            int isBindDialogStoreId = (int) SharedPreferencesUtils.getParam(getActivity(), Constants.SHARED_PREFERENCES_KEY_IS_STORE_BIND_DIALOG, 0);
            MyLog.e("yang", "isBindDialogStoreId==" + isBindDialogStoreId);
            if (isBindDialogStoreId > 0 && UserHelper.getInstance().isLogined()) {
                BindDialog(getActivity().getString(R.string.bind_store_title), getActivity().getString(R.string.sure_bind), getActivity().getString(R.string.cancle_bind), isBindDialogStoreId);
                SharedPreferencesUtils.setParam(getActivity(), Constants.SHARED_PREFERENCES_KEY_IS_STORE_BIND_DIALOG, 0);
            }
        }
        mSwipeLayout.setOnRefreshListener(this);

    }

    public void getPermissions() {
        rxPermissions.request(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(@NonNull Boolean aBoolean) throws Exception {
                        if (aBoolean) {
                            initUnbindStore();
                            MyLog.e("yang", "获取权限成功");
//                            PhoneUtils.ShowToastMessage(getActivity(), "获取权限成功");
                        } else {
//                            PhoneUtils.ShowToastMessage(getActivity(), "获取权限失败");
                            initUnbindStore();
                        }
                    }
                });
    }

    /**
     *
     * @param type 0 -隐藏， 1-下显示  2-上显示
     */
    private void setArrowStatus(int type){
       int srcId = R.mipmap.home_xia;
        switch (type){
            case 0:
                srcId = R.color.transparent;
                break;
            case 1:
                srcId = R.mipmap.home_xia;
                break;
            case 2:
                srcId = R.mipmap.home_shang;
                break;
        }

        Drawable rightDrawable = getResources().getDrawable(srcId);
        rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight());
        tvStoreName.setCompoundDrawables(null, null, rightDrawable, null);
    }

    private void initUnbindStore() {
        rlNoLoginTip.setVisibility(View.VISIBLE);
        llUnbindView.setVisibility(View.VISIBLE);
        llBindView.setVisibility(View.GONE);
        imgStoreHeadPortrait.setVisibility(View.GONE);
//        imgPopuwindowMenu.setVisibility(View.GONE);
        setArrowStatus(0);
        if (UserHelper.getInstance().isLogined()) {
            rlNoLoginTip.setVisibility(View.GONE);
        } else {
            rlNoLoginTip.setVisibility(View.VISIBLE);
        }
        tvStoreName.setText("当前门店");
        initLoc();
    }


    //获取公告列表2489
    public void getBulletin() {
        final BulletinListApi bulletinListApi = new BulletinListApi(new HttpOnNextListener<BulletinModel>() {
            @Override
            public void onNext(final BulletinModel result) {

                bulletinModelList.clear();
                if (result.getList() != null && result.getList().size() > 0) {
                    bulletinModelList.addAll(result.getList());
                    if (result.getList().size() == 1) {
                        bulletinModelList.addAll(result.getList());
                    }
                } else {
                    BulletinModel.ListBean listBean = new BulletinModel.ListBean();
                    listBean.setTitle("暂无公告");
//                    listBean.setMaraueeTitle("暂无公告");
                    bulletinModelList.add(listBean);
                }
                marqueeView.startWithList(bulletinModelList);
                marqueeView.setOnItemClickListener(new MarqueeView.OnItemClickListener() {
                    @Override
                    public void onItemClick(int position, TextView textView) {
                        if (marqueeView.getNotices().size() > 1)
                            IntentUtils.startBulletin(getActivity(), bulletinModelList.get(position).getInfoId() + "");
                    }
                });
                // 在代码里设置自己的动画
//                marqueeView.startWithList(info, R.anim.anim_bottom_in, R.anim.anim_top_out);
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
            }
        }, (RxAppCompatActivity) getActivity());
        bulletinListApi.setSession(UserHelper.getInstance().getSession(getActivity()));
        bulletinListApi.setStoreId(SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");

        bulletinListApi.setPage("1");
        bulletinListApi.setSize("5");
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(bulletinListApi);
    }


    private void initBindStore() {
        MyLog.e("yang", "initBindStore");

        llUnbindView.setVisibility(View.GONE);
        imgUnbindScan.setVisibility(View.GONE);
        llBindView.setVisibility(View.VISIBLE);
        imgStoreHeadPortrait.setVisibility(View.VISIBLE);
//        imgPopuwindowMenu.setVisibility(View.VISIBLE);
        setArrowStatus(1);
        mAdView.setRlBannerVisiable(View.INVISIBLE);
        mAdView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        if (null != locationClient) {
            locationClient.stopLocation();
            locationClient.onDestroy();
        }
        rlNoLoginTip.setVisibility(View.GONE);
        mChainStoresList = new ArrayList<>();

        BulletinModel.ListBean listBean = new BulletinModel.ListBean();
        listBean.setTitle("暂无公告");
        bulletinModelList.add(listBean);
        marqueeView.startWithList(bulletinModelList);

        rvGoods1.setAdapter(storeGoodsListTagAdapter1 = new StoreGoodsListTagAdapter(getActivity()));
        GridLayoutManager gridLayoutManager1 = new GridLayoutManager(getActivity(), 2);
        gridLayoutManager1.setSpanSizeLookup(storeGoodsListTagAdapter1.obtainGridSpanSizeLookUp(2));
        rvGoods1.setLayoutManager(gridLayoutManager1);
        rvGoods1.setNestedScrollingEnabled(false);
        rvGoods1.addItemDecoration(new DividerGridItemDecoration(getActivity(), 7f, R.drawable.shape_recyclerview_divider_decoration_commen));

        rvGoods2.setAdapter(storeGoodsListTagAdapter2 = new StoreGoodsListTagAdapter(getActivity()));
        GridLayoutManager gridLayoutManager2 = new GridLayoutManager(getActivity(), 2);
        gridLayoutManager2.setSpanSizeLookup(storeGoodsListTagAdapter2.obtainGridSpanSizeLookUp(2));
        rvGoods2.setLayoutManager(gridLayoutManager2);

        rvGoods2.setNestedScrollingEnabled(false);
        rvGoods2.addItemDecoration(new DividerGridItemDecoration(getActivity(), 7f, R.drawable.shape_recyclerview_divider_decoration_commen));

        rvGoods3.setAdapter(storeGoodsListTagAdapter3 = new StoreGoodsListTagAdapter(getActivity()));
        GridLayoutManager gridLayoutManager3 = new GridLayoutManager(getActivity(), 2);
        gridLayoutManager3.setSmoothScrollbarEnabled(true);
        gridLayoutManager3.setSpanSizeLookup(storeGoodsListTagAdapter3.obtainGridSpanSizeLookUp(2));
        rvGoods3.setLayoutManager(gridLayoutManager3);
        rvGoods3.addItemDecoration(new DividerGridItemDecoration(getActivity(), 7f, R.drawable.shape_recyclerview_divider_decoration_commen));


        storeGoodsListTagAdapter1.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position, Object o) {
                Intent intent = new Intent(getActivity(), GoodsDetailActivity.class);
                MyStoreGoodsListTagEntity listBean = (MyStoreGoodsListTagEntity) o;
                intent.putExtra("goodsId", listBean.getGoodsId());
                startActivity(intent);
            }
        });
        storeGoodsListTagAdapter2.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position, Object o) {
                Intent intent = new Intent(getActivity(), GoodsDetailActivity.class);
                MyStoreGoodsListTagEntity listBean = (MyStoreGoodsListTagEntity) o;
                intent.putExtra("goodsId", listBean.getGoodsId());
                startActivity(intent);
            }
        });
        storeGoodsListTagAdapter3.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position, Object o) {
                Intent intent = new Intent(getActivity(), GoodsDetailActivity.class);
                MyStoreGoodsListTagEntity listBean = (MyStoreGoodsListTagEntity) o;
                intent.putExtra("goodsId", listBean.getGoodsId());
                startActivity(intent);
            }
        });


        packageExpandableAdapter = new PackageExpandableAdapter(new ArrayList<MultiItemEntity>());
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
        rvStorePackage.setLayoutManager(layoutManager);
        rvStorePackage.setAdapter(packageExpandableAdapter);

        packageExpandableAdapter.setOnItemClickListener(new PackageExpandableAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int servicePackageId, View view) {
                Intent ti = new Intent(getActivity(), PackageCardDetailActivity.class);
                ti.putExtra("servicePackageId", servicePackageId);
                MyLog.e("yang", "packageExpandableAdapter/////servicePackageId==" + servicePackageId);
                startActivity(ti);
            }
        });


        packageExpandableAdapter.setOnBuyItemClickListener(new PackageExpandableAdapter.OnBuyItemClickListener() {
            @Override
            public void onBuyItemClick(EnpandableStorePackageEntity enpandableStorePackageEntity, View view) {
                int numbers = enpandableStorePackageEntity.getCurrentCount();
                double price = enpandableStorePackageEntity.getmPrice() * numbers;
                int servicePackageId = enpandableStorePackageEntity.getServicePackageId();
                if (price == 0) {
                    helpDialog("温馨提示", "是否进行购买套餐", "确定", "取消", numbers + "", servicePackageId + "");
                } else {
                    Intent ti = new Intent(getActivity(), BuyStorePackageActivity.class);
                    ti.putExtra("totalPrice", price);
                    ti.putExtra("servicePackageId", servicePackageId+"");
                    ti.putExtra("storeId", (int) SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0));
                    ti.putExtra("numbers", numbers);
                    startActivity(ti);
                }
            }
        });

        onRefresh();
    }

    public void onRefresh() {
//        if (!UserHelper.getInstance().isLogined()) {
//            return;
//        }
        mLoadView.ShowLoadView();
        int mBindStoreId = (int) SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0);
        if (mBindStoreId != 0) {
            MyLog.e("yang", "REFRESH_BIND_COMPLETE");
            mHandler.sendEmptyMessageDelayed(REFRESH_BIND_COMPLETE, 2000);
        } else {
            MyLog.e("yang", "REFRESH_UNBIND_COMPLETE");
            mHandler.sendEmptyMessageDelayed(REFRESH_UNBIND_COMPLETE, 2000);
        }

    }

    private void getHotGoods2() {

        if (UserHelper.getInstance().getSessionInfoModel(getActivity()) != null && (int) SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) > 0) {
            StoreGoodsListByTagApi storeGoodsListApi = new StoreGoodsListByTagApi(new HttpOnNextListener<StoreGoodsListTagEntity>() {
                @Override
                public void onNext(StoreGoodsListTagEntity model) {
                    List<StoreGoodsListTagEntity.GoodsListBean> list1 = model.getGoodsList();
                    List<StoreGoodsListTagEntity.GoodsList1Bean> list2 = model.getGoodsList1();
                    List<StoreGoodsListTagEntity.GoodsList2Bean> list3 = model.getGoodsList2();
                    storeGoodsListTagAdapter1.clear();
                    storeGoodsListTagAdapter2.clear();
                    storeGoodsListTagAdapter3.clear();
                    if (list1 != null && list1.size() > 0) {
                        llStoreGoods1.setVisibility(View.VISIBLE);
                        List<MyStoreGoodsListTagEntity> myList1 = new ArrayList<>();
                        for (int i = 0; i < list1.size(); i++) {
                            myList1.add(new MyStoreGoodsListTagEntity(list1.get(i).getGoodsId(), list1.get(i).getGoodsSpecValueSalesCount(),
                                    list1.get(i).getGoodsName(), list1.get(i).getGoodsLogo(), list1.get(i).getPrice(),
                                    list1.get(i).getStoreMemberPrice()));
                        }
                        storeGoodsListTagAdapter1.addAll(myList1);
                    } else {
                        llStoreGoods1.setVisibility(View.GONE);
                    }
                    if (list2 != null && list2.size() > 0) {
                        llStoreGoods2.setVisibility(View.VISIBLE);
                        List<MyStoreGoodsListTagEntity> myList2 = new ArrayList<>();
                        for (int i = 0; i < list2.size(); i++) {
                            myList2.add(new MyStoreGoodsListTagEntity(list2.get(i).getGoodsId(), list2.get(i).getGoodsSpecValueSalesCount(),
                                    list2.get(i).getGoodsName(), list2.get(i).getGoodsLogo(), list2.get(i).getPrice(),
                                    list2.get(i).getStoreMemberPrice()));
                        }
                        storeGoodsListTagAdapter2.addAll(myList2);
                    } else {
                        llStoreGoods2.setVisibility(View.GONE);
                    }

                    if (list3 != null && list3.size() > 0) {
                        llStoreGoods3.setVisibility(View.VISIBLE);
                        List<MyStoreGoodsListTagEntity> myList3 = new ArrayList<>();
                        for (int i = 0; i < list3.size(); i++) {
                            myList3.add(new MyStoreGoodsListTagEntity(list3.get(i).getGoodsId(), list3.get(i).getGoodsSpecValueSalesCount(),
                                    list3.get(i).getGoodsName(), list3.get(i).getGoodsLogo(), list3.get(i).getPrice(),
                                    list3.get(i).getStoreMemberPrice()));
                        }
                        storeGoodsListTagAdapter3.addAll(myList3);
                    } else {
                        llStoreGoods3.setVisibility(View.GONE);
                    }


                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    MyLog.e("yang", e.toString());

                }
            }, (RxAppCompatActivity) getActivity());
            storeGoodsListApi.setSession(UserHelper.getInstance().getSessionInfoModel(getActivity()).getSession());
            storeGoodsListApi.setStoreId(SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
            HttpManager manager = HttpManager.getInstance();
            manager.doHttpDeal(storeGoodsListApi);
        }

    }


    @Override
    protected void updateViews() {

    }


    private void getStoreInfoData() {
        OwnerStoreInfoApi ownerStoreInfoApi = new OwnerStoreInfoApi(new HttpOnNextListener<StoreDetailInfoModel>() {
            @Override
            public void onNext(StoreDetailInfoModel model) {
                setStoreInfoData(model);
            }

            @Override
            public void onCacheNext(String cache) {
                super.onCacheNext(cache);
                Gson gson = new Gson();
                Type type = new TypeToken<BaseResultEntity<StoreDetailInfoModel>>() {
                }.getType();
                BaseResultEntity<StoreDetailInfoModel> model = gson.fromJson(cache, type);
                setStoreInfoData(model.getData());
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                PhoneUtils.ShowToastMessage(getActivity(), e.getMessage());
            }

        }, (RxAppCompatActivity) (getContext()));
        ownerStoreInfoApi.setStoreId(SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(ownerStoreInfoApi);
    }

    private void getChainStoreData() {
        String url = Constants.APP_API_BASE + Constants.OWN_BRANCHSTORE;
        RequestParams params = new RequestParams(url);
        params.addBodyParameter("session", UserHelper.getInstance().getSessionInfoModel(getActivity()).getSession());
        params.addBodyParameter("storeId", SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
        params.addBodyParameter("gprsX", "0");
        params.addBodyParameter("gprsY", "0");
        MyLog.e("hep", SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                MyLog.e("hep", result);
                try {
                    String data = PhoneUtils.checkResponseFlag(getActivity(), result);
                    if (data != null) {
                        //UserHelper.getInstance().saveChainStores(getActivity(), data);
                        mChainStoresList.clear();
                        //mChainStoresList = UserHelper.getInstance().getmChainStoresList(getActivity());
                        mChainStoresList = new Gson().fromJson(data, new TypeToken<List<ChainStoresModel>>() {
                        }.getType());
                        if (mChainStoresList.size() == 1) {
//                            imgPopuwindowMenu.setVisibility(View.INVISIBLE);
                            setArrowStatus(0);
                        } else {
//                            imgPopuwindowMenu.setVisibility(View.VISIBLE);
                            setArrowStatus(1);
                        }
                    }
                } catch (Exception e) {

                }


            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                MyLog.e("yang", "onError==" + ex.toString());
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    private void setStoreInfoData(StoreDetailInfoModel model) {
        //门店名称
        tvStoreName.setText(model.getStoreInfo().getStoreName());
        //顶部门店头像
        GlideUtils.loadImage(getActivity(), model.getStoreInfo().getStroeLogo(), imgStoreHeadPortrait, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
            @Override
            public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

            }

            @Override
            public void onLoadingError(String source, Exception e) {

            }
        }, R.mipmap.default_icon, R.mipmap.default_icon);
    }


    //    banners
    private void getBannersData() {
        OwnStoreBannerApi ownStoreBannerApi = new OwnStoreBannerApi(new HttpOnNextListener<List<StoreDetailBannersModel>>() {
            @Override
            public void onNext(List<StoreDetailBannersModel> data) {
                MyLog.e("yang", "data==" + data.size());
                bannersModel = data;
                mImageUrl.clear();
                mImageUrlweb.clear();
                if (data != null && data.size() > 0) {
                    for (int i = 0; i < data.size(); i++) {
                        mImageUrl.add(data.get(i).getPicUrl() + "-320%7C1080");
                        mImageUrlweb.add(data.get(i).getDescription());
                    }
                } else {
//                    mImageUrl.add("");
//                    mImageUrlweb.add("");
                }
                mAdView.setImageResources(mImageUrl, mImageUrlweb, mAdCycleViewListener);
                //2018.3.26 wangyang新增没有banner隐藏
                MyLog.e("yang", "mImageUrl====" + mImageUrl.size());
                if (mImageUrl == null || mImageUrl.size() == 0) {
                    mAdView.setVisibility(View.GONE);
                } else {
                    mAdView.setVisibility(View.VISIBLE);
                }

            }

            @Override
            public void onCacheNext(String string) {
                super.onCacheNext(string);
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
            }

        }, (RxAppCompatActivity) (getContext()));
        ownStoreBannerApi.setSession(UserHelper.getInstance().getSessionInfoModel(getActivity()).getSession());
        ownStoreBannerApi.setStoreId(SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(ownStoreBannerApi);
    }

    private ImageCycleView.ImageCycleViewListener mAdCycleViewListener = new ImageCycleView.ImageCycleViewListener() {
        @Override
        public void onImageClick(int position, View imageView) {
            // TODO 单击图片处理事件
            if (bannersModel.size() > 0) {
                String contactType = bannersModel.get(position).getContactType();
                if (contactType.equals("package")) {
                    Intent ti = new Intent(getActivity(), PackageCardDetailActivity.class);
                    ti.putExtra("servicePackageId", Integer.valueOf(bannersModel.get(position).getContactId()));
                    startActivity(ti);
                } else if (contactType.equals("h5")) {
//                    webViewRequestParam.setParams("session=" + UserHelper.getInstance().getSessionInfoModel(
//                            getActivity()).getSession() + +"&storeServiceId="
//                            + model.getStoreServiceId());
                    String url = Constants.APP_API_BASE + Constants.PUB_SHOP_ACTIVITYH5;
                    WebViewRequestParam webViewRequestParam = new WebViewRequestParam(url);
                    webViewRequestParam.setRequestMethod(REQUEST_POST);
                    webViewRequestParam.setParams("session=" + UserHelper.getInstance().getSessionInfoModel(
                            getActivity()).getSession() + "&goodsActivityId=" + bannersModel.get(position).getContactId());
                    Intent intent = new Intent(getActivity(), WebViewActivity.class);
                    intent.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam);
                    intent.putExtra("type", "h5");
                    startActivityForResult(intent, 848);
                } else if (contactType.equals("url")) {
                    WebViewRequestParam webViewRequestParam = new WebViewRequestParam(bannersModel.get(position).getContactId());
                    webViewRequestParam.setRequestMethod(REQUEST_POST);
//                    webViewRequestParam.setParams();
                    Intent intent = new Intent(getActivity(), WebViewActivity.class);
                    intent.putExtra("type", "url");
                    intent.putExtra("title", bannersModel.get(position).getDescription());
                    intent.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam);

                    startActivityForResult(intent, 848);
                }
            }

        }

        @Override
        public void displayImage(String imageURL, ImageView imageView) {
            GlideUtils.loadImage(getActivity(), imageURL, imageView, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.default_banner, R.mipmap.default_banner);

        }
    };


    //显示下拉菜单
    public void showPopupWindow() {
        View customView = getActivity().getLayoutInflater().inflate(R.layout.store_head_popupwindow_recycleview, null, false);
        popupwindow = new PopupWindow(customView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        poprecycleview = (RecyclerView) customView.findViewById(R.id.poprecyclerView);
        popupwindow.setAnimationStyle(R.style.PopupWindowAnimation);
        ColorDrawable cd = new ColorDrawable(0x000000);
        popupwindow.setBackgroundDrawable(cd);
        popupwindow.setBackgroundDrawable(new BitmapDrawable());
        // 设置点击窗口外边窗口消失
        popupwindow.setOutsideTouchable(true);
        // 设置此参数获得焦点，否则无法点击
        popupwindow.setFocusable(true);
        PhoneUtils.backgroundAlpha(getActivity(), 0.4f);
        popupwindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                PhoneUtils.backgroundAlpha(getActivity(), 1f);
//                RotateAnimation myAnimationRotate = new RotateAnimation(0.0f, 0.0f,
//                        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//                imgPopuwindowMenu.startAnimation(myAnimationRotate);
                setArrowStatus(1);
//                myAnimationRotate.setDuration(500);
//                myAnimationRotate.setFillAfter(true);

            }
        });
//        MyLog.e("hep",mChainStoresList.size()+);
        homePopMenuAdapter = new StorePopuMenuSelectAdapter(getActivity(), mChainStoresList, tvStoreName.getText().toString().trim());
        poprecycleview.setLayoutManager(new LinearLayoutManager(getActivity()));
        poprecycleview.addItemDecoration(new RecycleViewDivider(getActivity(), LinearLayoutManager.VERTICAL, R.drawable.shape_recyclerview_divider_decoration));
        poprecycleview.setAdapter(homePopMenuAdapter);
        homePopMenuAdapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener<ChainStoresModel>() {
            @Override
            public void onItemClick(int position, ChainStoresModel model, View view) {
                selectStore(model);
                if (popupwindow != null && popupwindow.isShowing()) {
                    popupwindow.dismiss();
                    return;
                }

            }
        });
    }

    public void selectStore(ChainStoresModel model) {
        tvStoreName.setText(model.getStoreName());
        UserHelper.getInstance().setSelectStoreId(getActivity(), model.getStoreId());
        ownerInfoModel.setStoreName(model.getStoreName());
        UserHelper.getInstance().setOwnerInfoModel(getActivity(), ownerInfoModel);
        MyLog.e("yang", "切换门店id==" + model.getStoreId());
        RxBus.getDefault().post(Constants.SELECT_STORE_ID, new CommonEvent("切换门店"));
        getBannersData();
        getBulletin();
        getHotGoods2();
        getStorePackage();
        GlideUtils.loadImage(getActivity(), model.getStroeLogo(), imgStoreHeadPortrait, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
            @Override
            public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {
            }

            @Override
            public void onLoadingError(String source, Exception e) {

            }
        }, R.mipmap.default_icon, R.mipmap.default_icon);
    }

    //  定位回调监听事件
    private double longItude;
    private double latItude;
    AMapLocationListener mAMapLocationListener = new AMapLocationListener() {
        @Override
        public void onLocationChanged(AMapLocation amapLocation) {

            if (amapLocation != null) {
                if (amapLocation.getErrorCode() == 0) {
                    if (isFirstLoc) {
                        longItude = amapLocation.getLongitude();
                        latItude = amapLocation.getLatitude();
                        getNearStoreList(longItude, latItude);
                        MyLog.e("yang", "定位成功");

                    }
                } else {
                    //显示错误信息ErrCode是错误码，errInfo是错误信息，详见错误码表。
                    MyLog.e("yang", "location Error, ErrCode:"
                            + amapLocation.getErrorCode() + ", errInfo:"
                            + amapLocation.getErrorInfo());
                }
            }
        }
    };

    //longItude 经度  latItude纬度
    private void getNearStoreList(double longItude, double latItude) {
        NearStoreListApi nearStoreListApi = new NearStoreListApi(new HttpOnNextListener<List<NearStoreListModel>>() {
            @Override
            public void onNext(List<NearStoreListModel> list) {
                setNearStoreList(list);
                MyLog.e("yang", "请求数据list==" + list.size());
            }

            @Override
            public void onCacheNext(String cache) {
                super.onCacheNext(cache);
                Gson gson = new Gson();
                Type type = new TypeToken<BaseResultEntity<List<NearStoreListModel>>>() {
                }.getType();
                BaseResultEntity<List<NearStoreListModel>> cacheList = gson.fromJson(cache, type);
                setNearStoreList(cacheList.getData());
                MyLog.e("yang", "缓存");
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                PhoneUtils.ShowToastMessage(getActivity(), e.getMessage());
            }

        }, (RxAppCompatActivity) (getContext()));
        nearStoreListApi.setGprsX(longItude + "");
        nearStoreListApi.setGprsY(latItude + "");
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(nearStoreListApi);


    }

    private void setNearStoreList(List<NearStoreListModel> list) {
        isFirstLoc = false;
        mNearlist = list;
        MyLog.e("yang", "isFirstLoc=======" + isFirstLoc);
        if (list != null && list.size() > 0) {
            nearStoreListModelOne = list.get(0);
            tvLocation.setText(nearStoreListModelOne.getStoreLocation());
            if (nearStoreListModelOne.getMin() < 1) {
                tvDistance.setText("距离 " + (int) (nearStoreListModelOne.getMin() * 1000) + "米以内");
            } else {
                tvDistance.setText("距离 " + nearStoreListModelOne.getMin() + "km");
            }
            tvUnbindStoreName.setText(nearStoreListModelOne.getStoreName());
            GlideUtils.loadImage(getActivity(), nearStoreListModelOne.getStroeLogo(), imgStoreBanner, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.store_default_bg, R.mipmap.store_default_bg);
        }


    }


    @Override
    public void onResume() {
        super.onResume();
        boolean isFirstGuide = (Boolean) SharedPreferencesUtils.getParam(getActivity(), Constants.SHARED_PREFERENCES_KEY_IS_FIRST_STORE_GUIDE, true);
        if (!UserHelper.getInstance().isLogined() && isFirstGuide) {
            // newPeopleBindGuide();
        }
        SharedPreferencesUtils.remove(Constants.SHARED_PREFERENCES_KEY_IS_STORE_BIND);

        if (MainActivity.isNeedBind) {
            MainActivity.isNeedBind = false;
            MyLog.e("yang", "WebViewActivity.bindStoreId==" + WebViewActivity.bindStoreId);
            if (WebViewActivity.bindStoreId != 0) {
                BindStoreRequest(WebViewActivity.bindStoreId);
            }

        }

    }

    //  新手引导绑定
    private void newPeopleBindGuide() {
        final GuideHelper guideHelper = new GuideHelper(getActivity());
        View view1 = guideHelper.inflate(R.layout.custom_view_guide_three);
        GuideHelper.TipData tipCustom1 = new GuideHelper.TipData(view1, tvStoreName);
        view1.findViewById(R.id.img_three_guide_know).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                guideHelper.dismiss();
            }
        });
        tipCustom1.setLocation(0, DisplayUtils.dipToPix(getActivity(), 110));
        guideHelper.addPage(false, tipCustom1);
        guideHelper.show(false);
        SharedPreferencesUtils.setParam(getActivity(), Constants.SHARED_PREFERENCES_KEY_IS_FIRST_STORE_GUIDE, false);

    }


    //定位初始化控件配置
    private void initLoc() {
        locationClient = new AMapLocationClient(getActivity());
        //设置定位回调监听
        locationClient.setLocationListener(mAMapLocationListener);
        //初始化定位参数
        locationOption = new AMapLocationClientOption();
        //设置定位模式为高精度模式，Battery_Saving为低功耗模式，Device_Sensors是仅设备模式
        locationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        //设置是否返回地址信息（默认返回地址信息）
        locationOption.setNeedAddress(true);
        //设置是否只定位一次,默认为false
        locationOption.setOnceLocation(false);
        //设置是否强制刷新WIFI，默认为强制刷新
        locationOption.setWifiActiveScan(true);
        //设置是否允许模拟位置,默认为false，不允许模拟位置
        locationOption.setMockEnable(false);
        //设置定位间隔,单位毫秒,默认为2000ms
        locationOption.setInterval(2000);
        //给定位客户端对象设置定位参数
        locationClient.setLocationOption(locationOption);
        //启动定位
        locationClient.startLocation();

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        RxBus.getDefault().unRegister(this);
        if (null != locationClient) {
            locationClient.stopLocation();
            locationClient.onDestroy();
            locationClient = null;
            locationOption = null;
        }
    }

    private void BindDialog(String title, String sure, String cancle, final int storeId) {
        new UniversalDialog(getActivity()).builder().setTitle(title)
                .setPositiveButton(sure, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        BindStoreRequest(storeId);
                    }
                }).setNegativeButton(cancle, new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        }).show();
    }

    private void BindStoreRequest(final int storeId) {
        ownerInfoModel = UserHelper.getInstance().getOwnerInfoModel(getActivity());
        BindStoreApi bindStoreApi = new BindStoreApi(new HttpOnNextListener<StoreDataModel>() {
            @Override
            public void onNext(StoreDataModel model) {
                Gson gson = new GsonBuilder().create();
                String data = gson.toJson(model);
                MyLog.e("asus", "data" + data);
                UserHelper.getInstance().saveChainStores(getActivity(), data);
                MessageHelper.getInstance().reset();
                EMClient.getInstance().login(UserHelper.getInstance().getUserInfoModel(getActivity()).getImKey(), UserHelper.getInstance().getUserInfoModel(getActivity()).getImPasswd(), new EMCallBack() {//回调
                    @Override
                    public void onSuccess() {
                        MessageHelper.getInstance().getUserProfileManager().setCurrentUser(UserHelper.getInstance().getUserInfoModel(getActivity().getApplicationContext()).getNickName(),
                                UserHelper.getInstance().getUserInfoModel(getActivity().getApplicationContext()).getUserLogo());
                        EMClient.getInstance().groupManager().loadAllGroups();
                        EMClient.getInstance().chatManager().loadAllConversations();
                        MyLog.d("King", "登录聊天服务器成功！");
                    }

                    @Override
                    public void onProgress(int progress, String status) {

                    }

                    @Override
                    public void onError(int code, String message) {
                        MyLog.d("King", "登录聊天服务器失败！" + code + "|" + message);
                    }
                });
                for (int i = 0; i < model.getChainStores().size(); i++) {
                    if (model.getChainStores().get(i).getStoreId() == storeId) {
                        String storeName = model.getChainStores().get(i).getStoreName();
                        ownerInfoModel.setStoreName(storeName);
                        break;
                    }
                }
                ownerInfoModel.setStoreId(storeId);
                ownerInfoModel.setBindStoreId(storeId);
                UserHelper.getInstance().setOwnerInfoModel(getActivity(), ownerInfoModel);
                UserHelper.getInstance().setSelectStoreId(getActivity(), storeId);
                SharedPreferencesUtils.setParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, storeId);
                PhoneUtils.ShowToastMessage(getActivity(), "绑定成功");
                SharedPreferencesUtils.remove(Constants.SHARED_PREFERENCES_KEY_IS_STORE_BIND);
                initBindStore();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                e.printStackTrace();
                PhoneUtils.ShowToastMessage(getActivity(), e.getMessage());
            }
        }, (RxAppCompatActivity) (getContext()));

        bindStoreApi.setSession(UserHelper.getInstance().getSessionInfoModel(getActivity()).getSession());
        bindStoreApi.setStoreId(storeId + "");
        HttpManager manager = HttpManager.getInstance();
        manager.doHttpDeal(bindStoreApi);
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK && requestCode == NOBIND_TYPE) {
            imgUnbindScan.setVisibility(View.GONE);
            initBindStore();
        }

        if (resultCode == RESULT_OK && requestCode == BIND_TYPE) {
            imgUnbindScan.setVisibility(View.GONE);
            initBindStore();
            MyLog.e("yang", "888888888888888");
        }


        if (resultCode == ZXingConstants.ScanRequestCode) {
            /**
             * 拿到解析完成的字符串
             */
            String result = data.getStringExtra(ZXingConstants.ScanResult);
            try {
                String[] spStr = result.split("=");
                String storeId = spStr[1];
                getStoreInfo(storeId);
            } catch (Exception e) {
                PhoneUtils.ShowToastMessage(getActivity(), "请扫描袋鼠店管家门店二维码");
            }

        }

    }


    //得到扫描数据
    private void getStoreInfo(String storeId) {
        mLoadView.ShowLoadView();
        String url = Constants.APP_API_BASE + Constants.OWN_STOREINFO;
        RequestParams params = new RequestParams(url);
        params.addBodyParameter("storeId", storeId);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                MyLog.e("yang", "扫描成功==" + result);
                String data = PhoneUtils.checkResponseFlag(getActivity(), result);
                if (data != null) {
                    Gson gson = new GsonBuilder().create();
                    StoreDetailInfoModel model = gson.fromJson(data, StoreDetailInfoModel.class);
                    Intent ti = new Intent(getActivity(), NoBindStoreDetailActivity.class);
                    ti.putExtra("storeName", model.getStoreInfo().getStoreName());
                    ti.putExtra("stroeLogo", model.getStoreInfo().getStroeLogo());
                    ti.putExtra("description", model.getStoreInfo().getDescription());
                    ti.putExtra("serviceNumber", model.getStoreInfo().getServiceNumber());
                    ti.putExtra("storeLocation", model.getStoreInfo().getStoreLocation());
                    ti.putExtra("gprsX", model.getStoreInfo().getGprsX());
                    ti.putExtra("gprsY", model.getStoreInfo().getGprsY());
                    ti.putExtra("storeId", model.getStoreInfo().getStoreId());
                    ti.putExtra("banners", (Serializable) model.getResList());
                    ti.putExtra("isScan", true);
                    startActivityForResult(ti, NOBIND_TYPE);
                    mLoadView.CancleLoadView();

                }

            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                MyLog.e("yang", "扫描失败==" + ex.toString());
                mLoadView.CancleLoadView();
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });

    }

    //6.0系统打开相机
    public void onClickCamera() {
        Acp.getInstance(getActivity()).request(new AcpOptions.Builder().setPermissions(Manifest.permission.CAMERA).build(),
                new AcpListener() {
                    @Override
                    public void onGranted() {
                        Intent intent = new Intent(getActivity(), CaptureActivity.class);
                        startActivityForResult(intent, ZXingConstants.ScanRequestCode);
                    }

                    @Override
                    public void onDenied(List<String> permissions) {
                        PhoneUtils.ShowToastMessage(getActivity(), permissions.toString() + "权限拒绝");
                    }
                });

    }


    @OnClick({R.id.tv_unbind_login, R.id.img_unbind_scan, R.id.ll_bind_store, R.id.ll_enter_store, R.id.tv_enter_near_store,
            R.id.line_home_popupwindow, R.id.ll_store_title, R.id.ll_store_payment, R.id.ll_store_subscribe,
            R.id.ll_store_recharge, R.id.ll_store_coupon, R.id.ll_store_goods, R.id.ll_store_package, R.id.ll_store_sec_kill, R.id.ll_store_more,
            R.id.ll_goods1, R.id.ll_goods2, R.id.ll_goods3})
    public void viewOnClick(View view) {
        switch (view.getId()) {
            case R.id.tv_unbind_login:
                SharedPreferencesUtils.setParam(getActivity(), Constants.SHARED_PREFERENCES_KEY_IS_STORE_BIND, true);
                if (checkLoginState()) {

                }
                break;
            case R.id.img_unbind_scan:
                if ((Build.VERSION.SDK_INT >= 23)) {
                    onClickCamera();
                } else {
                    Intent intent = new Intent(getActivity(), CaptureActivity.class);
                    startActivityForResult(intent, ZXingConstants.ScanRequestCode);
                }
                break;
            case R.id.ll_bind_store:
                if (nearStoreListModelOne != null && nearStoreListModelOne.getStoreId() != 0) {
                    SharedPreferencesUtils.setParam(getActivity(), Constants.SHARED_PREFERENCES_KEY_IS_STORE_BIND_DIALOG, nearStoreListModelOne.getStoreId());
                    SharedPreferencesUtils.setParam(getActivity(), Constants.SHARED_PREFERENCES_KEY_IS_STORE_BIND, true);
                    if (checkLoginState()) {
                        BindDialog(getActivity().getString(R.string.bind_store_title), getActivity().getString(R.string.sure_bind), getActivity().getString(R.string.cancle_bind), nearStoreListModelOne.getStoreId());
                    }
                }

                break;
            case R.id.ll_enter_store:
                if (nearStoreListModelOne != null) {
                    Intent ti = new Intent(getActivity(), NoBindStoreDetailActivity.class);
                    ti.putExtra("storeName", nearStoreListModelOne.getStoreName());
                    ti.putExtra("stroeLogo", nearStoreListModelOne.getStroeLogo());
                    ti.putExtra("description", nearStoreListModelOne.getDescription());
                    ti.putExtra("serviceNumber", nearStoreListModelOne.getServiceNumber());
                    ti.putExtra("storeLocation", nearStoreListModelOne.getStoreLocation());
                    ti.putExtra("gprsX", nearStoreListModelOne.getGprsX());
                    ti.putExtra("gprsY", nearStoreListModelOne.getGprsY());
                    ti.putExtra("storeId", nearStoreListModelOne.getStoreId());
                    ti.putExtra("banners", (Serializable) nearStoreListModelOne.getResList());
                    ti.putExtra("isScan", false);
                    startActivityForResult(ti, NOBIND_TYPE);
                }

                break;
            case R.id.tv_enter_near_store:
                Intent ti = new Intent(getActivity(), StoreListActivity.class);
                ti.putExtra("nearList", (Serializable) mNearlist);
                startActivityForResult(ti, BIND_TYPE);
                break;
            case R.id.line_home_popupwindow:
                if (popupwindow != null && popupwindow.isShowing()) {
                    popupwindow.dismiss();
                    return;
                } else {
                    try {
//                        if (imgPopuwindowMenu.getVisibility() == View.VISIBLE) {
                            if (mChainStoresList.size() > 0) {
                                showPopupWindow();
                                popupwindow.showAsDropDown(view);
//                                RotateAnimation myAnimationRotate = new RotateAnimation(0.0f, 180.0f,
//                                        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//                                imgPopuwindowMenu.startAnimation(myAnimationRotate);
                                setArrowStatus(2);
//                                myAnimationRotate.setDuration(500);
//                                myAnimationRotate.setFillAfter(true);

                            }
//                        }
                    } catch (Exception e) {
                    }

                }
                break;
            case R.id.ll_store_title:
                startActivity(new Intent(getActivity(), BulletinListActivity.class));
                break;
            case R.id.ll_store_payment:
                startActivity(new Intent(getActivity(), PaidActivity.class));
                break;
            case R.id.ll_store_subscribe:
                int storeId = Integer.parseInt(SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
                ChainStoresModel chainStores = null;
                for (ChainStoresModel chainStoresModel : mChainStoresList) {
                    if (storeId == chainStoresModel.getStoreId()) {
                        chainStores = chainStoresModel;
                    }
                }
                startActivity(new Intent(getActivity(), SelectBespokeActivity.class).putExtra("isClose", true).putExtra("chainStores", chainStores));
                break;
            case R.id.ll_store_recharge:
                isRechargeSwitch();
                break;
            case R.id.ll_store_coupon:
                Intent ti3 = new Intent(getActivity(), GetCouponsCenterActivity.class);
                ti3.putExtra("isPlatform", false);
                startActivity(ti3);
                break;
            case R.id.ll_store_goods:
                Intent ti4 = new Intent(getActivity(), HotShopClassifyActivity.class);
                ti4.putExtra("goodsType", STORE_TYPE);
                startActivity(ti4);
                break;
            case R.id.ll_store_package:
                startActivity(new Intent(getActivity(), PackageCardProjectActivity.class));
                break;
            case R.id.ll_store_sec_kill:
                startActivity(new Intent(getActivity(), SecKillActivity.class).putExtra("fromType", STORE_TYPE));
                break;
            case R.id.ll_store_more:
                startActivity(new Intent(getActivity(), StoreMoreActivity.class));
                break;
            case R.id.ll_goods1:
                Intent ti5 = new Intent(getActivity(), GoodsListActivity.class);
//                intent.putExtra("fromType", 0);
                ti5.putExtra("goodsType", 1);
                ti5.putExtra("title", "店长推荐");
                ti5.putExtra("labels", "店长推荐");
                startActivity(ti5);
                break;
            case R.id.ll_goods2:
                Intent ti6 = new Intent(getActivity(), GoodsListActivity.class);
//                intent.putExtra("fromType", 0);
                ti6.putExtra("goodsType", 1);
                ti6.putExtra("title", "热门商品");
                ti6.putExtra("labels", "热门商品");
                startActivity(ti6);
                break;
            case R.id.ll_goods3:
                Intent ti7 = new Intent(getActivity(), GoodsListActivity.class);
//                intent.putExtra("fromType", 0);
                ti7.putExtra("goodsType", 1);
                ti7.putExtra("title", "新品上市");
                ti7.putExtra("labels", "新品上市");
                startActivity(ti7);
                break;

        }

    }


    private void isRechargeSwitch() {
        mLoadView.ShowLoadView();
        String url = Constants.APP_API_BASE + Constants.OWN_MARKETING_GETTOPUPPLANCUSTOMSWITHSETTING;
        RequestParams params = new RequestParams(url);
        params.addBodyParameter("session", UserHelper.getInstance().getSession(getActivity()));
        params.addBodyParameter("storeId", SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                MyLog.e("yang", "onSuccess==" + result);
                String flag = JsonUtil.getJsonValuesString(result, "flag");
                String data = JsonUtil.getJsonValuesString(result, "data");
                String exp = JsonUtil.getJsonValuesString(result, "exp");
                if (flag.equals("true")) {
                    Intent ti2 = new Intent(getActivity(), RechargeActivity.class);
                    ti2.putExtra("customSwitch", data);
                    ti2.putExtra("storeId", (int) SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0));
                    startActivity(ti2);
                } else {
                    PhoneUtils.ShowToastMessage(getActivity(), exp);
                }


            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                MyLog.e("yang", "onError==" + ex.toString());
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {
                mLoadView.CancleLoadView();
            }
        });

    }


    //    获取门店套餐
    private void getStorePackage() {
        StorePackageApi storePackageApi = new StorePackageApi(new HttpOnNextListener<List<StorePackageEntity.DataBean>>() {
            @Override
            public void onNext(List<StorePackageEntity.DataBean> mList) {
                MyLog.e("yang", "onNext==" + mList.size());
                ArrayList<MultiItemEntity> multiItemEntities = new ArrayList<>();
                if (mList != null && mList.size() > 0) {
                    llRecommendStorePackage.setVisibility(View.VISIBLE);
                    for (int i = 0; i < mList.size(); i++) {
                        EnpandableStorePackageEntity subItem = new EnpandableStorePackageEntity();
                        subItem.setItemList(mList.get(i).getItemList());
                        subItem.setValidityType(mList.get(i).getValidityType());
                        subItem.setFixTimeType(mList.get(i).getFixTimeType());
                        subItem.setFixTimeValue(mList.get(i).getFixTimeValue());
                        subItem.setStartTime(mList.get(i).getStartTime());
                        subItem.setEndTime(mList.get(i).getEndTime());
                        subItem.setOriginalPrice(mList.get(i).getOriginalPrice());
                        subItem.setmPrice(mList.get(i).getPrice());
                        subItem.setGiveAmount(mList.get(i).getGiveAmount());
                        subItem.setSingleUsrMaxCount(mList.get(i).getSingleUsrMaxCount());
                        subItem.setServicePackageId(mList.get(i).getServicePackageId());
                        mList.get(i).addSubItem(subItem);
                        multiItemEntities.add(mList.get(i));
                    }

                    MyLog.e("yang", "multiItemEntities==" + multiItemEntities.size());
                    packageExpandableAdapter.setNewData(multiItemEntities);
                } else {
                    llRecommendStorePackage.setVisibility(View.GONE);
                }

            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                MyLog.e("yang", "onError==" + e.toString());

            }
        }, (RxAppCompatActivity) (getContext()));


        storePackageApi.setSession(UserHelper.getInstance().getSessionInfoModel(getActivity()).getSession());
        storePackageApi.setStoreId(SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
        HttpManager manager = HttpManager.getInstance();
        manager.doHttpDeal(storePackageApi);

    }

    private void helpDialog(String title, String msg, String sure, String cancle, final String numbers, final String servicePackageId) {
        new UniversalDialog(getActivity()).builder()
                .setTitle(title)
                .setMsg(msg)
                .setPositiveButton(sure, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        payDepositAmount(servicePackageId, numbers);
                    }
                }).setNegativeButton(cancle, new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        }).show();
    }


    private void payDepositAmount(String servicePackageId, String numbers) {
        mLoadView.ShowLoadView();
        String url = Constants.APP_API_BASE + Constants.OWN_ORDER_BUYPACKAGE;
        RequestParams params = new RequestParams(url);
        params.addBodyParameter("session", UserHelper.getInstance().getSessionInfoModel(getActivity()).getSession());
        params.addBodyParameter("storeId", SharedPreferencesUtils.getParam(getActivity(), UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
        params.addBodyParameter("useStoreBalance", "true");
        params.addBodyParameter("servicePackageId", servicePackageId);
        params.addBodyParameter("numbers", numbers);
//        params.addBodyParameter("pushPackageId", pushPackageId + "");
        MyLog.e("yang", "params==" + params);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                MyLog.e("yang", "套餐付款onSuccess==" + result);
                String data = PhoneUtils.checkResponseFlag(getActivity(), result);
                if (data != null) {
                    if (data.equals("")) {
                        RxBus.getDefault().post(Constants.BUY_PACKAGE_SUCCESS_CODE, new CommonEvent("购买套餐"));
                        PhoneUtils.ShowToastMessage(getActivity(), "购买该套餐成功");
                    }

                }


            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                MyLog.e("yang", "套餐付款onError==" + ex.toString());

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {
                mLoadView.CancleLoadView();
            }
        });
    }
}
